/**
 * Copyright 2006-2008 Michele Mostarda ( michele.mostarda@gmail.com ).
 * All Rights Reserved.
 * <p/>
 * Licensed under the Apache License, Version 2.0 (the 'License');
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * <p/>
 * http://www.apache.org/licenses/LICENSE-2.0
 * <p/>
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an 'AS IS' BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.graphnav.demo;

import org.graphnav.swing.GraphFrame;
import org.graphnav.swing.Node;
import org.graphnav.swing.event.GraphPanelEvent;
import org.graphnav.swing.event.GraphPanelListener;
import org.graphnav.demo.model.JenaGraphModel;

import javax.swing.JFrame;
import java.awt.Point;
import java.awt.Toolkit;

/**
 * Provides the main access point. Used for test purposes.
 */
public class JenaBrowserTest {

        public static void main(String[] args) throws ClassNotFoundException {

        GraphFrame frame = new GraphFrame( JenaGraphModel.createFromURL() );

        frame.getGraphPanel().addGraphPanelListener(

             new GraphPanelListener() {

                public void nodesSelected(GraphPanelEvent gpe) {
                    //System.out.println("nodesSelected: ");
                    //printNodes(gpe.getSelectedNodes());
                }

                public void nodesDeselected(GraphPanelEvent gpe) {
                    //System.out.println("nodesSelected: ");
                    //printNodes(gpe.getSelectedNodes());
                }

                public void nodesMoved(GraphPanelEvent gpe) {
                    //System.out.println("Nodes moved!");
                }

                 public void nodesOverlapped(GraphPanelEvent gpe) {
                     //Empty.
                 }

                 public void nodeCollapsed(GraphPanelEvent gpe) {
                     //System.out.println("org.graphnav.swing.Node collapsed");
                 }

                 public void nodeExpanded(GraphPanelEvent gpe) {
                     //System.out.println("node expanded.");
                 }

                 public void panelResized(GraphPanelEvent gpe) {
                     //System.out.println("panel resized.");
                 }

                 void printNodes(Node[] nodes) {
                    //System.out.println("Nodes: " + nodes.length);
                    for(int i = 0; i < nodes.length; i++) {
                        System.out.println(nodes[i] + ";");
                    }
                }
            }

        );

        frame.setSize(800, 600);
        frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        double screenWidth  = Toolkit.getDefaultToolkit().getScreenSize().getWidth();
        double screenHeight = Toolkit.getDefaultToolkit().getScreenSize().getHeight();
        Point frameLocation = new Point( (int) ( screenWidth - frame.getWidth() ) / 2, (int) ( screenHeight - frame.getHeight() ) / 2);
        frame.setLocation(frameLocation);
        frame.setVisible(true);
    }

}
